/**
 *  *2010-3-25 下午12:42:29  add 
 */
package com.base.myproject.server.Comet;

import java.sql.ResultSet;
import java.util.Date;
import java.util.Hashtable;

import com.base.myproject.server.database.PoolMan;

/**
 * 用户预约
 * @author Administrator
 *2010-3-25
 * javazgw@gmail.com
 */
public class Reservation extends CometObject {

	CometContainer c ;
	long sleep=10000;
	PoolMan pm = new PoolMan();
	Hashtable<String ,String> ht = new Hashtable<String ,String>();
	public Reservation(CometContainer c)
	{
		this.c = c;
		c.add(this);
	}
	@Override
	public Object Judge() {
		// TODO Auto-generated method stub
		return "dddd";
	}

	@Override
	public boolean hasnew() {
		
		return true;
	}

	@Override
	public long sleep() {
		
		return sleep;
	}

	@Override
	public String getCOName() {
		// TODO Auto-generated method stub
		return "Reservation";
	}
	@Override
	public synchronized void run() {
		while(true)
		{
		//System.out.println(""+getCOName());
		
		try {
			Thread.sleep(sleep);
			wait();
		} catch (InterruptedException e) {
		
			e.printStackTrace();
		}
		try {
			ResultSet rs = pm.executeQuery("select triggername,triggerdate from triggertable");
			while(rs.next())
			{
				String triggername = rs.getString("triggername");
				String triggerdate = rs.getString("triggerdate");
				if(ht.containsKey(triggername))
				{
					System.out.println(ht.get(triggername)+"---"+triggerdate+"--"+(ht.get(triggername).equals(triggerdate)));
					if(!ht.get(triggername).equals(triggerdate))
					{
						ht.put(triggername, triggerdate);
						c.ht.put(getCOName(), "现在时间："+new Date()+(new String("--999")));
					}
					
				}
				else
				{
					ht.put(triggername, triggerdate);
					c.ht.put(getCOName(), "现在时间："+new Date()+(new String("--999")));
			
				}
			}
			
		} catch (Exception e) {
			//	失败后延时10秒执行
			sleep+=10000;
			e.printStackTrace();
		}
		
		//c.ht.put(getCOName(), "现在时间："+new Date()+(new String("--06789")));
		}
		
	}
	

}
